<style>
<!--
.top_li{
	float:right !important;
	line-height: 2em;
}
#creat_div , #user_id-label , #is_edit-label , #is_add-label{
	display:none;
}
	#feedback { font-size: 1.4em; }
	#selectable .ui-selecting { background: #FECA40; }
	#selectable .ui-selected { background: #F39814; color: white; }
	#selectable { list-style-type: none; margin: 0; padding: 0;}
	#selectable li { margin: 3px; padding: 0.4em; height: 18px;text-align: center; }

-->
</style>
	<table width="100%" height="500">
		<tr>
			<td width="10%" align="left" valign="top" id="menu_tree_td">

			<div class="flexigrid ui-datepicker ui-widget ui-widget-content  ui-corner-all" id="accountsList" style="width: 100px; display: block;">
				<div class="mDiv ui-datepicker-header ui-widget-header  ui-corner-all">
					<div class="ftitle">导航栏</div>
					<div class="ptogtitle" title="Minimize/Maximize Table"><span></span></div>
				</div>
				<div>
					<ol id="selectable">
						<li class="ui-widget-content ui-selected" target="inBox">收件箱</li>
						<li class="ui-widget-content" target="outBox">发件箱</li>
						<li class="ui-widget-content" target="draft">草稿箱</li>				
						<li class="ui-widget-content" target="recycleBox">回收站</li>
					</ol>
				</div>
			</div>
			</td>
			<td align="left" valign="top">
				<table id="flex_grid">
					<!--THIS IS GRID-->
				</table>
				<table id="flex_grid_outbox">
					<!--THIS IS GRID-->
				</table>
				<table id="flex_grid_draft">
					<!--THIS IS GRID-->
				</table>				
				<table id="flex_grid_recyclebox">
					<!--THIS IS GRID-->
				</table>
			</td>
		</tr>
	</table>


<script><!--
$(function() {
	iniInbox();
	$("#selectable").selectable({
		 selected: function(event, ui){
			if(ui){
				switch($(ui.selected).attr("target")){
					case 'inBox':
						iniInbox();
					break;
					case 'outBox':
						iniOutbox();
					break;
					case 'draft':
						iniDraftbox("draft");
					break;
					case 'recycleBox':
						iniRecycleBox();
					break;
					default:
						iniInbox();
					break;
				}
				window.grids.flexReload();
			}
		 }
	});

	//recive mail in background
	mailTools.startRecivePorcess();
});
var
iniInbox = function(){
	//收件箱
	$(window.grids).hide();
	window.grids = $("#flex_grid").flexigrid({
		url: '<?php echo $this->pagePath;?>/mail/inbox',
		dataType: 'json',
		colModel : [
			{display: '状态', name : 'state', width : 30, sortable : true, align: 'left',process:getState},
			{display: '发件人', name : 'from', width : 200, sortable : true, align: 'left'},
			{display: '主题', name : 'subject', width : 400, sortable : true, align: 'left'},
			{display: '发件时间', name : 'send_time', width : 120, sortable : false, align: 'left'},
			{display: '收件人', name : 'to', width : 200, sortable : true, align: 'left'},
			{display: '收件时间', name : 'create_time', width : 120, sortable : false, align: 'left'},
			{display: '负责人', name : 'user', width : 80, sortable : true, align: 'left'},
			{display: '注意事项', name : 'note', width : 150, sortable : true, align: 'left'}
		],
		searchitems : [
            {display: '发件人' ,name : 'name', isdefault: true}
		],
		buttons : [
			<?php if($this->allow('add','user','')){?>
			{name: '查看',bclass:"view", onpress : viewInfo},
			<?php } ?>
			<?php if($this->allow('add','user','')){?>
			{name: '标记为已读',bclass:"add", onpress :setReaded},
			<?php } if($this->allow('add','user','')){?>
			{name: '标记为未读',bclass:"delete", onpress :setunReaded},
			<?php } ?>
			<?php if($this->allow('add','user','')){?>
			{name: '分配给',bclass:"send", onpress :setUser},
			<?php } ?>
			<?php if($this->allow('delete','user','')){?>
			{name: '新邮件',bclass:"add", onpress :newMail},
			<?php } ?>
			<?php if($this->allow('edit','user','')){?>
			{name: '删除',bclass:"delete", onpress :setDeleted},
			<?php } ?>
			<?php if($this->allow('delete','user','')){?>
			{name: '刷新',bclass:"reload", onpress :reloadGrid},
			<?php } ?>
			{separator:true}
		], 
		sortname: "send_time",
		sortorder: "DESC",
		singleSelect:true,//是否单选
		resizable:false,		
		usepager: true,
		hideOnSubmit:1,//禁用遮照
		title: '收件箱',
		useRp: true,
		rp: 15,
		showTableToggleBtn: true,
		id:"accountsList",
		width: "99%",
		height: 310,
		onRowClick:function($e){
		},
		onRowDblclick:function($e){
			//双击查看详情
			var id = $e.attr("id").toString().replace("row","") || "0";
			viewInfo(id);
		}
	}).show();
}
,iniOutbox = function(){
	//发件箱
	$(window.grids).hide();
	window.grids = $("#flex_grid_outbox").flexigrid({
		url: '<?php echo $this->pagePath;?>/mail/outbox',
		dataType: 'json',
		colModel : [
			{display: '发件人', name : 'from', width : 200, sortable : true, align: 'left'},
			{display: '收件人', name : 'to', width : 200, sortable : true, align: 'left'},			
			{display: '主题', name : 'subject', width : 50, sortable : true, align: 'left'},
			{display: '审核状态', name : 'approve_status', width : 50, sortable : true, align: 'left',process:gridHelper.Aapprove},	
			{display: '发送状态', name : 'state_send', width : 50, sortable : true, align: 'left',process:getSendState},			
			{display: '写信时间', name : 'create_time', width : 50, sortable : false, align: 'left'},
			{display: '发送时间', name : 'last_edit_time', width : 50, sortable : false, align: 'left'},			
			{display: '负责人', name : 'user', width : 80, sortable : true, align: 'left'}
		],
		searchitems : [
            {display: '发件人' ,name : 'name', isdefault: true}
		],
		buttons : [
			<?php if($this->allow('delete','user','')){?>
			{name: '新邮件',bclass:"add", onpress :newMail},
			<?php } ?>
			<?php if($this->allow('add','user','')){?>
			{name: '查看',bclass:"view", onpress : viewInfoOutBox},
			<?php } ?>
			{separator:true}
		], 
		sortname: "id",
		sortorder: "DESC",
		//singleSelect:true,//是否单选
		usepager: true,
		hideOnSubmit:1,//禁用遮照
		title: '发件箱',
		useRp: true,
		rp: 15,
		showTableToggleBtn: true,
		id:"accountsList",
		width: "99%",
		height: 310,
		onRowClick:function($e){
		},
		onRowDblclick:function($e){
			//双击查看详情
			var id = $e.attr("id").toString().replace("row","") || "0";
			//viewInfoOutBox(id);
		}
	}).show();	
}
,iniDraftbox = function(){
	//草稿箱
	$(window.grids).hide();
	window.grids = $("#flex_grid_draft").flexigrid({
		url: '<?php echo $this->pagePath;?>/mail/outbox?query=0&qtype=edite_status',
		dataType: 'json',
		colModel : [
			{display: '发件人', name : 'from', width : 200, sortable : true, align: 'left'},
			{display: '收件人', name : 'to', width : 200, sortable : true, align: 'left'},			
			{display: '主题', name : 'subject', width : 50, sortable : true, align: 'left'},
			{display: '审核状态', name : 'approve_status', width : 50, sortable : true, align: 'left',process:gridHelper.Aapprove},	
			{display: '发送状态', name : 'state_send', width : 50, sortable : true, align: 'left',process:getSendState},			
			{display: '写信时间', name : 'create_time', width : 50, sortable : false, align: 'left'},
			{display: '发送时间', name : 'last_edit_time', width : 50, sortable : false, align: 'left'},			
			{display: '负责人', name : 'user', width : 80, sortable : true, align: 'left'}
		],
		searchitems : [
            {display: '发件人' ,name : 'name', isdefault: true}
		],
		buttons : [
			<?php if($this->allow('delete','user','')){?>
			{name: '编辑',bclass:"add", onpress :newMail},
			<?php } ?>
			{separator:true}
		], 
		sortname: "id",
		sortorder: "DESC",
		//singleSelect:true,//是否单选
		usepager: true,
		hideOnSubmit:1,//禁用遮照
		title: '发件箱',
		useRp: true,
		rp: 15,
		showTableToggleBtn: true,
		id:"accountsList",
		width: "99%",
		height: 310,
		onRowClick:function($e){
		},
		onRowDblclick:function($e){
			//双击查看详情
			var id = $e.attr("id").toString().replace("row","") || "0";
			//viewInfo(id);
		}
	}).show();	
}
,iniRecycleBox = function(){
	//回收箱
	$(window.grids).hide();
	window.grids = $("#flex_grid_recyclebox").flexigrid({
		url: '<?php echo $this->pagePath;?>/mail/recyclebox',
		dataType: 'json',
		colModel : [
			{display: '发件人', name : 'from', width : 200, sortable : true, align: 'center'},
			{display: '主题', name : 'title', width : 50, sortable : true, align: 'left'},
			{display: '状态', name : 'state_admin', width : 50, sortable : true, align: 'left'},			
			{display: '时间', name : 'create_time', width : 50, sortable : false, align: 'left'},
			{display: '负责人', name : 'user', width : 80, sortable : true, align: 'left'}
		],
		buttons : [
			<?php if($this->allow('add','user','')){?>
			{name: '查看',bclass:"view", onpress : viewInfo},
			<?php } ?>
			<?php if($this->allow('edit','user','')){?>
			{name: '删除',bclass:"edit", onpress :realDelete},
			<?php } ?>
			<?php if($this->allow('delete','user','')){?>
			{name: '回收',bclass:"edit", onpress :recycle},
			<?php } ?>
			{separator:true}
		], 
		sortname: "id",
		sortorder: "asc",
		//singleSelect:true,//是否单选
		usepager: true,
		hideOnSubmit:1,//禁用遮照
		title: '回收站',
		useRp: true,
		rp: 15,
		showTableToggleBtn: true,
		id:"accountsList",
		width: "99%",
		height: 310,
		onRowClick:function($e){
		},
		onRowDblclick:function($e){
			//双击查看详情
			var id = $e.attr("id").toString().replace("row","") || "0";
			//viewInfo(id);
		}
	}).show();
}
//获得阅读状态
,getState = function(a,b){
	a.innerHTML = (a.innerHTML > 0)?"<font color='green'>已读</font>":"<font color='red'>未读</font>";
}
//获得发送状态
,getSendState = function(a,b){
	a.innerHTML = (a.innerHTML > 0)?"<font color='green'>已发送</font>":"<font color='red'>等待发送</font>";
}
//设置阅读状态
,setState = function(id,state){
	var data = {"id":id,"state":state};
	$.ajax({
		url:'<?php echo $this->pagePath;?>/mail/setstate',
		data:data,
		type: 'post',
		dataType:'json',
		success:function(data){
			if(data.status){
				//设置成功
				window.grids.flexReload();
			}else{
				alert("设置失败 : " + data.msg);
			}
		},
		error:function(){
			alert("设置失败");
		}
	});
}
//设置阅读状态为已读
,setReaded = function(name,e){
	if($('#flex_grid .trSelected').length > 0){
		var id = $(e).find("tr.trSelected").attr("id").replace("row","");
		setState(id,1);
	}else{
		alert('请选择一项需要编辑的数据。');
	}
}
//设置阅读状态为未读
,setunReaded = function(name,e){
	if($('#flex_grid .trSelected').length > 0){
		var id = $(e).find(".trSelected").attr("id").replace("row","");
		setState(id,0);
	}else{
		alert('请选择一项需要编辑的数据。');
	}
}
//分配负责人
,setUser = function(name,e){
	if($('#flex_grid .trSelected').length > 0){
		var id = $(e).find(".trSelected").attr("id").replace("row","");
		var top = $(this).offset().top;
		zendform.zendFormCreat(e,{
			url:"<?php echo $this->pagePath;?>/mail/setuser/id/"+id,
			dialog:{
				title:"分配责任人",
				width:258,
				height:238,
				position:[null,top]
			}
		});
	}else{
		alert('请选择一项需要编辑的数据。');
	}
}
//删除
,setDeleted = function(name,e){
	if($('#flex_grid .trSelected').length > 0){
		var id = $(e).find(".trSelected").attr("id").replace("row","");
		var data = {"id":id};
		$.ajax({
			url:'<?php echo $this->pagePath;?>/mail/setdeleted',
			data:data,
			type: 'post',
			dataType:'json',
			success:function(data){
				if(data.status){
					//设置成功
					window.grids.flexReload();
				}else{
					alert("删除失败 : " + data.msg);
				}
			},
			error:function(){
				alert("删除失败");
			}
		});
	}else{
		alert('请选择一项需要删除的数据。');
	}
}
//刷新
,reloadGrid = function(name,e){
	return window.grids.flexReload();
	if($('#flex_grid .trSelected').length > 0){
		var id = $(e).find(".trSelected").attr("id").replace("row","");
		setState(id,0);
	}else{
		alert('请选择一项需要删除的数据。');
	}
}
//彻底删除
,realDelete = function(name,e){
	return window.grids.flexReload();
	if($(grids).find('.trSelected').length > 0){
		var id = $(e).find(".trSelected").attr("id").replace("row","");
		var data = {"id":id};
		$.ajax({
			url:'<?php echo $this->pagePath;?>/mail/del',
			data:data,
			type: 'post',
			dataType:'json',
			success:function(data){
				if(data.status){
					//设置成功
					window.grids.flexReload();
				}else{
					alert("删除失败 : " + data.msg);
				}
			},
			error:function(){
				alert("删除失败");
			}
		});
	}else{
		alert('请选择一项需要删除的数据。');
	}
}
//回收
,recycle = function(name,e){
	if($(grids).find('.trSelected').length > 0){
		var id = $(e).find(".trSelected").attr("id").replace("row","");
		var data = {"id":id};
		$.ajax({
			url:'<?php echo $this->pagePath;?>/mail/recycle',
			data:data,
			type: 'post',
			dataType:'json',
			success:function(data){
				if(data.status){
					//设置成功
					window.grids.flexReload();
				}else{
					alert("删除失败 : " + data.msg);
				}
			},
			error:function(){
				alert("删除失败");
			}
		});
	}else{
		alert('请选择一项需要删除的数据。');
	}
}
//双击查看详情
,viewInfo = function(id,e,boxtype){
	boxtype = boxtype || "inbox";
	id = Number(id) || $(e).find(".trSelected")[0].id.toString().replace("row","") || "0";
	$("<div />",{"id":"cust_info_"+id,"class":"home_log_list"}).html("<img src='<?php echo $this->pagePath;?>/css/flexigrid_images/load.gif'/>").dialog({
		title:"邮件内容",
		width:990,
		height:480,
		position:[null,top],
		close:function(){$(this).dialog("destroy").remove()}
	});
	$("#"+"cust_info_"+id).load("<?php echo $this->pagePath;?>/mail/viewmail/boxtype/"+boxtype+"/id/"+id,function(){
		$(".customer_accordion").accordion({
			collapsible: true
		});
		//viewPress(id,e,$("#customer_accordion_press_div"));
	});
	(boxtype == "inbox") && setState(id,1);
}
//双击查看发件箱邮件，复用viewInfo
,viewInfoOutBox = function(id,e){
	viewInfo(id,e,"outbox");
}
//新邮件
,newMail = function(){
	window.location.href = "<?php echo $this->pagePath;?>/mail/add";
}
;
--></script>
<div id="creat_div"></div>
<div id="edit_div"></div>